<template>
        <div class="operationBox">
                <!-- 搜索框 -->
                <!-- <searchBox ref="searchBox" :formInline='formInline' :form='form' @search="onSubmit">
                    <template #defaultBtn>
                        <el-button  type="primary"  style="width:120px;" @click="clickDownloadQrCode" :disabled="idsStr == ''">批量下载二维码</el-button>
                    </template>
                </searchBox> -->
                <assembly-Integration :formInline='formInline' :btnList="btnList" @search="onSubmit" @btnListClick="btnListClick" />
                <!-- 列表 -->
                <div class="tabel_box">
                    <lpj-table-vue :baseNum='paginationMes.per_page*(paginationMes.current_page-1)' ref="lpjTable" :tableData="tableData" :tableHeaderData="tableHeaderData[8]" @linkBtnFn="linkBtnFn" @pointerClick="pointerClick" @handleSelectionChange="handleSelectionChange" @selectionFn="selectionChange"></lpj-table-vue>
                </div>
                <!-- 页码 -->
                <pagination v-if="paginationMes.total && paginationMes.total>10" align="right" :paginationMes="paginationMes" @sizeChangeFn="sizeChangeFn" @currentChangeFn="currentChangeFn"></pagination>
                <progressLoad :isShow="progressIsShow" :progress="progress" @close="progressClose"/>
        </div>
</template>

<script>
    import { getPropertyLists,downloadQrCode } from "./api"
    import progressLoad from '@/components/qrCodeMain/progressLoad'
    import Pagination from "@/components/Pagination"
    import LpjTableVue from "@/components/LpjTableVue"
    // import searchBox from "@/components/searchBox"/**搜索框 */
    import constObj from '@/config/const' /**表头常数 */
    import assemblyIntegration from "@/components/assemblyIntegration"/** 新版搜索框 */
    export default {
        components:{Pagination,LpjTableVue,progressLoad,assemblyIntegration},
        data(){
            return {
                progressIsShow:false,
                progress:0,
                form:{f_name:'',f_code:'', f_cid:'', c_status:'',users:'',start_time:'',end_time:'',departments:'',wh_id:''},/**搜索框form */
                formInline:[ /**搜索框 */
                    {type:'input',value:'f_name',label:'资产名称',placeholder:'请输入',hide:false},
                    {type:'input',value:'f_code',label:'资产编码',placeholder:'请输入',hide:false},
                    {type:'select',value:'f_cid',label:'资产分类',placeholder:'请选择',options:[],hasGroup:true,defaultProp:['id','category_name','cate'],treeProp:{children: 'cate',label: 'category_name'},hide:false},
                    {type:'select',value:'c_status',label:'资产状态',placeholder:'请选择',options:constObj.states,hasGroup:false,defaultProp:['id','name'],hide:false},
                    {type:'people',value:'users',label:'领用人',placeholder:'请输入',options:[],hide:false}
                ],
                btnList:[
                    {
                        type:'batchDownQrCode',
                        label:'批量下载二维码',
                        status:true
                    }
                ],
                action:'table',/**table 为表格，add为新增页面 */
                tableData:[],
                /*分页 数据*/
                paginationMes:{per_page:10,current_page:1,total:0},
                /**操作列表表头数据 */
                tableHeaderData:JSON.parse(JSON.stringify(constObj.tableHeaderOfmyAssetsManager)),
                idsStr:''        
            }
        },
        created(){
           this.initList(this.form,1)
        },
        watch:{
            '$store.state.warehouseOfAssetsManager'(newData,old){
                this.initList(this.form,1)
            }
        },
        methods:{
            btnListClick(item){
                switch(item.type){
                    case 'batchDownQrCode': // 数据导出
                    console.log(item.label)
                    this.clickDownloadQrCode()
                    break;
                }
            },
            // 关闭进度条
            progressClose(){

            },
            initList(params,page = this.paginationMes.current_page){
               let obj = {
                   ...params,
                   wh_id:this.$store.state.warehouseOfAssetsManager,
                   num:this.paginationMes.per_page,
                   page:this.paginationMes.current_page
               }
               getPropertyLists(obj)
               .then((res)=>{
                   this.paginationMes.total = res.total
                   this.tableData = res.data
               })
            },
            // 下载二维码
            clickDownloadQrCode(){
                if(this.idsStr == ''){
                    this.$message({
                        showClose: true,
                        message: '需要下载的资产不能为空',
                        type: 'warning'
                    });
                    return false
                }
                let params = {
                    wh_id:this.$store.state.warehouseOfAssetsManager,
                    download_type:1,
                    ids:this.idsStr
                }
                downloadQrCode(params)
                .then(res=>{
                     this.downloadFile(res.qrcode_pdf_url)
                })

            },
            downloadFile(url){
                let that = this
                this.dd.biz.util.downloadFile({
                        url, 
                        name: `批量资产二维码.pdf`,
                        onProgress: function(msg){
                            if(msg.progress && msg.progress < 100){
                                that.progressIsShow = true
                                that.progress = msg.progress
                            }else{
                                 that.progressIsShow = false
                                 that.progress = 0
                            }
                        },
                        onSuccess : function(result) {
                        },
                        onFail : function() {}
                    })
            },
            selectionChange(params){
                   let idsArr = params.map((item,index)=>{return item.id})
                   this.idsStr = idsArr.join(',')
            },
            /**查询 */
            onSubmit(form,user,dept) {
                let params = {
                    ...this.form,
                    ...form,
                    users:user&&user.length?JSON.stringify(user):''
                }
                this.initList(params,1)
            },
            linkBtnFn(val,data){},
            pointerClick(data){
            },
            handleSelectionChange(selection){

            },
            /*操作列表分页传过来的 当前第几页 */
            currentChangeFn(val){
                this.paginationMes.current_page = val||1//当前页数
                this.initList(this.form,this.paginationMes.current_page)
            },
            /*操作列表分页传过来的 table每页的条数*/
            sizeChangeFn(val){
                this.paginationMes.current_page=1
                this.paginationMes.per_page = val||10//当前页数
                this.initList(this.form,this.paginationMes.current_page)
            },
        }
    }
</script>

<style lang="scss">
    .el-button--primary.is-disabled, .el-button--primary.is-disabled:active, .el-button--primary.is-disabled:focus, .el-button--primary.is-disabled:hover{
        color:#8C8C8C !important;
        background-color: rgba(255,255,255,0) !important;
        border: 1px solid rgba(223, 223, 223, 1);
    }
</style>